home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Icon / c / SetTextRJ < prev    next >
Text File  |  1995-07-08  |  2KB  |  63 lines

  1. /* Icon_SetTextRJ
  2.  * (c) Copyright 1993 Erik do Kort
  3.  */
  4.  
  5. #include <string.h>
  6.  
  7. #include "DeskLib:Icon.h"
  8. #include "DeskLib:Wimp.h"
  9. #include "DeskLib:WimpSWIs.h"
  10.  
  11.  
  12. extern void Icon_SetTextRJ(window_handle w, icon_handle i, char *text)
  13. /*
  14.  * Copies the text string into the icon's indirected string buffer (and redraws)
  15.  * This text is "right justified", meaning that if the text doesn't fit,
  16.  * it is truncated at the *LEFT*-hand side, and preceded by a '...' char
  17.  * If unable to set the text (incorrect icon type), it returns quietly
  18.  * If text passed in is a NULL pointer, sets icon text to '\0'
  19.  */
  20. {
  21.   icon_block  istate;
  22.   int         empty = 0;
  23.   caret_block caret;
  24.   int         len;
  25.  
  26.   if (text == NULL)
  27.     text = (char *)∅
  28.  
  29.   Wimp_GetIconState(w, i, &istate);
  30.   if (istate.flags.value & (icon_TEXT | icon_INDIRECTED))
  31.   {
  32.     /* Indirected text icon, so set text field - ensure no buffer overflow
  33.      */
  34.     register int  textlength = strlen(text) + 1 ;
  35.     register int  bufflength = istate.data.indirecttext.bufflen ;
  36.     register char *buffer    = istate.data.indirecttext.buffer ;
  37.     if ( bufflength < textlength )
  38.     {
  39.       text += textlength - bufflength ;
  40.       if ( bufflength > 2 )
  41.       {
  42.         *buffer++ = '\x8c' ;
  43.         text += 1 ;
  44.       }
  45.     }
  46.     strcpy(buffer, text) ;
  47.  
  48.     /* Ensure caret isn't beyond end of text */
  49.     Wimp_GetCaretPosition( &caret );
  50.     if ( caret.window == w && caret.icon == i )
  51.     {
  52.       len = strlen( istate.data.indirecttext.buffer );
  53.       if ( caret.index > len )
  54.       {
  55.         caret.index = len;
  56.         Wimp_SetCaretPosition( &caret );
  57.       }
  58.     }
  59.  
  60.     Wimp_SetIconState(w, i, 0, 0);
  61.   }
  62. }
  63.